﻿using MxWeiXinPF.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MxWeiXinPF.Web.admin.jiaoshuifei
{
    public partial class payment_record_list : Web.UI.ManagePage
    {
        protected int totalCount;
        protected int page;
        protected int pageSize;

        BLL.shuifei_payment_record actBll = new BLL.shuifei_payment_record();
        protected int wid = 0;
        protected string yuming = "";
        protected string keywords = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {

            ChkAdminLevel("jiaoshuifei_payment_record", MXEnums.ActionEnum.View.ToString()); //检查权限

            this.keywords = MXRequest.GetQueryString("keywords");

            this.pageSize = GetPageSize(10); //每页数量
            if (!Page.IsPostBack)
            { 
                RptBind(CombSqlTxt(keywords), "id desc,create_time desc");

            }
        }




        #region 数据绑定=================================
        private void RptBind(string _strWhere, string _orderby)
        {

            Model.wx_userweixin weixin = GetWeiXinCode();
            wid = weixin.id;

            this.page = MXRequest.GetQueryInt("page", 1);
            txtKeywords.Text = this.keywords;

            DataSet ds = actBll.GetList(this.pageSize, this.page, weixin.id, _strWhere, _orderby, out this.totalCount);

            
            this.rptList.DataSource = ds;
            this.rptList.DataBind();

            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("payment_record_list.aspx", "keywords={0}&page={1}", this.keywords, "__id__");
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);


        }
        #endregion

        #region 组合SQL查询语句==========================
        protected string CombSqlTxt(string _keywords)
        {
            StringBuilder strTemp = new StringBuilder();
            _keywords = _keywords.Replace("'", "");
            if (!string.IsNullOrEmpty(_keywords))
            {
                strTemp.Append("  (  openid like  '%" + _keywords + "%'   or consno like  '%" + _keywords + "%' or orderID like  '%" + _keywords + "%' ) ");
            }

            return strTemp.ToString();
        }
        #endregion

        #region 返回每页数量=============================
        private int GetPageSize(int _default_size)
        {
            int _pagesize;
            if (int.TryParse(Utils.GetCookie("payment_record_list_page_size"), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    return _pagesize;
                }
            }
            return _default_size;
        }
        #endregion

        //关健字查询
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Response.Redirect(Utils.CombUrlTxt("payment_record_list.aspx", "keywords={0}", this.txtKeywords.Text));
        }

        //设置分页数量
        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int _pagesize;
            if (int.TryParse(txtPageNum.Text.Trim(), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    Utils.WriteCookie("payment_record_list_page_size", _pagesize.ToString(), 14400);
                }
            }
            Response.Redirect(Utils.CombUrlTxt("payment_record_list.aspx", "keywords={0}", this.txtKeywords.Text));
        }

        

    }
}